import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
import { ImagesConst } from "../../resource/ImagesConst";
import { PetModelPanel } from "./PetModelPanel";
import { PetTileItem } from "./PetTileItem";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ResFileConst } from "../../resource/ResFileConst";
import { PetProcessBar } from "./PetProcessBar";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { PetAttrPanel } from "./PetAttrPanel";
import { PetInfoSkillListPanel } from "./skill/PetInfoSkillListPanel";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { BgLabelToolTip } from "../common/tooltip/BgLabelToolTip";
import { PetUtil } from "./info/PetUtil";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { PetColor } from "./info/PetColor";
import { CareerConfig } from "../../resource/CareerConfig";
import { ECareer } from "../../../../Message/Public/ECareer";
import { PetExperienceConfig } from "../../resource/PetExperienceConfig";
import { PetShareObject } from "./info/PetShareObject";
import { GameController } from "../../mvc/GameController";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
type int = number;
//class PetInfoPanel
    
    export  class PetInfoPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._fightAttrLabelArray = Language.getString(54554).split(",");
            this._baseAttrLabelArray = Language.getString(54553).split(",");
            this._skillItemArray = [];
            this.init();
            this.registToolTip();
            this.mouseEnabled = false;
            return;
        }

        /* internal  */getAdditionByGrowth(): string
        {
            var loc2=NaN;
            var loc1="";
            if (this._petInfo) 
            {
                loc2 = (this._petInfo.growth / 5 - 4) * (this._petInfo.level - 1);
                loc1 = "（+" + Math.floor(loc2) + "）";
            }
            return loc1;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 235, 265, this);
            this.addChild(new GImageBitmap("rolePetBg.jpg", 2, 2));
            ObjCreate.createBg(65, 140, 95, 20, this, ImagesConst.SelectedBg);
            this._petModel = new PetModelPanel();
            this._petModel.x = 120;
            this._petModel.y = 124;
            this.addChild(this._petModel);
            this._modelSprite = new Object /* flash.display.Sprite */();
            this._modelSprite.x = 0;
            this._modelSprite.y = 0;
            this.addChild(this._modelSprite);
            this._tileItem = new PetTileItem();
            this._tileItem.x = 10;
            this._tileItem.y = 10;
            this._modelSprite.addChild(this._tileItem);
            this._nameTxt = ObjCreate.createTextField("", 0, 10, 273, 20, this._modelSprite, GlobalStyle.textFormat2);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._sexTxt = ObjCreate.createTextField("", 200, 10, 50, 20, this._modelSprite, GlobalStyle.textFormat2);
            this._typeBtn = ObjCreate.createGLoadedButton("", 10, 40, 29, 26, this._modelSprite);
            this._jianBtn = ObjCreate.createGLoadedButton(ResFileConst.Jian, 10, 80, 29, 26, this._modelSprite);
            this._jianBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onJianBtnClickHandler);
            this._talentLabel = ObjCreate.createGTextField(Language.getString(54208), 85, 145, 35, 35, this._modelSprite);
            this._talentTxt = ObjCreate.createGTextField("", 103, 145, 57, 35, this._modelSprite);
            this._talentTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._rebornTimePic = ObjCreate.createBitmap("", 40, 45, this._modelSprite);
            this._baseSprite = new Object /* flash.display.Sprite */();
            this._baseSprite.x = 10;
            this._baseSprite.y = 180;
            this.addChild(this._baseSprite);
            ObjCreate.createTextField(Language.getString(54211), 0, 7, 50, 20, this._baseSprite);
            this._nameInput = ObjCreate.createGTextInput(50, 0, 105, 25, this._baseSprite);
            this._nameInput.maxChars = 6;
            this._nameInput.setStyle("textPadding", 4);
            ObjCreate.createTextField(Language.getString(54209), 0, 34, 50, 20, this._baseSprite);
            this._lifeBar = new PetProcessBar(ImagesConst.RedBar10);
            this._lifeBar.move(50, 34);
            this._lifeBar.setValue(0, 0);
            this._baseSprite.addChild(this._lifeBar);
            ObjCreate.createTextField(Language.getString(54569), 0, 60, 50, 20, this._baseSprite);
            this._lifespanBar = new PetProcessBar(ImagesConst.PurpleBar10);
            this._lifespanBar.move(50, 60);
            this._baseSprite.addChild(this._lifespanBar);
            this._levelTxt = ObjCreate.createTextField("", 160, 0, 30, 30, this._baseSprite, new GTextFormat(FontUtil.songtiName, 22, 15788607, true));
            this._levelTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            ObjCreate.createTextField(Language.getString(54216), 190, 10, 50, 20, this._baseSprite);
            this._attrSprite = new Object /* flash.display.Sprite */();
            this._attrSprite.x = 240;
            this.addChild(this._attrSprite);
            ObjCreate.createBg(0, 0, 155, 400, this._attrSprite);
            ObjCreate.createBg(2, 2, 90, 24, this._attrSprite, ImagesConst.TileBg);
            ObjCreate.createBg(2, 200, 90, 24, this._attrSprite, ImagesConst.TileBg);
            this._spiritTxt = ObjCreate.createTextField("", 5, 5, 95, 20, this._attrSprite, new GTextFormat(FontUtil.songtiName, 14, 15788607));
            this._spiritTxt.name = "spirit";
            this._spiritTxt.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onTxtMouseOverHandler);
            this._spiritTxt.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onTxtMouseOutHandler);
            this._fightAttrPanel = new PetAttrPanel(this._fightAttrLabelArray, GlobalStyle.textFormat4);
            this._fightAttrPanel.x = 5;
            this._fightAttrPanel.y = 30;
            this._attrSprite.addChild(this._fightAttrPanel);
            this._growthTxt = ObjCreate.createTextField("", 5, 203, 95, 20, this._attrSprite, new GTextFormat(FontUtil.songtiName, 14, 15788607));
            this._growthTxt.name = "growth";
            this._growthTxt.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onTxtMouseOverHandler);
            this._growthTxt.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onTxtMouseOutHandler);
            this._baseAttrPanel = new PetAttrPanel(this._baseAttrLabelArray, GlobalStyle.textFormat5);
            this._baseAttrPanel.x = 5;
            this._baseAttrPanel.y = 228;
            this._attrSprite.addChild(this._baseAttrPanel);
            this._skillSprite = new Object /* flash.display.Sprite */();
            this._skillSprite.x = 0;
            this._skillSprite.y = 270;
            this.addChild(this._skillSprite);
            ObjCreate.createBg(0, 0, 235, 130, this._skillSprite);
            ObjCreate.createBg(2, 2, 90, 24, this._skillSprite, ImagesConst.TileBg);
            this._skillSprite.addChild(new GImageBitmap("PetSkillLabel.png", 5, 5));
            ObjCreate.createBg(182, 40, 80, 1, this._skillSprite, ImagesConst.SeptalLine).rotation = 90;
            this._skillListPanel = new PetInfoSkillListPanel();
            this._skillListPanel.x = 19;
            this._skillListPanel.y = 3;
            this._skillSprite.addChild(this._skillListPanel);
            return;
        }

        /* internal  */registToolTip(): void
        {
            var loc3=null;
            var loc1=HTMLUtil.addColor(Language.getString(54228), "#FFFFFF");
            this._talentLabel.toolTipData = loc1;
            this._talentTxt.toolTipData = loc1;
            this._jianBtn.toolTipData = HTMLUtil.addColor(Language.getString(54229), "#FFFFFF");
            var loc2=[];
            var loc4=0;
            while (loc4 < 12) 
            {
                loc3 = HTMLUtil.addColor(GameDefConfig.instance.getPetAttrDesc(loc4), "#FFFFFF");
                loc2.push(loc3);
                ++loc4;
            }
            this._fightAttrPanel.regLabelTip(loc2.slice(0, 7));
            this._baseAttrPanel.regLabelTip(loc2.slice(7, 12));
            return;
        }

        /* internal  */set rebornTimeBitmapData(arg1: int)
        {
            if (arg1 > 0) 
            {
                this._rebornTimePic.bitmapData = GlobalClass.getBitmapData("mountReinLevel_" + arg1);
            }
            else 
            {
                this._rebornTimePic.bitmapData = null;
            }
            return;
        }

        /* internal  */onTxtMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (this._petInfo) 
            {
                loc1 = arg1.target as Object /* flash.text.TextField */;
                if (this._labelTip == null) 
                {
                    this._labelTip = new BgLabelToolTip();
                    this._labelTip.x = 155;
                }
                if (!this._attrSprite.contains(this._labelTip)) 
                {
                    this._attrSprite.addChild(this._labelTip);
                }
                if (loc1.name != "spirit") 
                {
                    if (loc1.name == "growth") 
                    {
                        this._labelTip.data = PetUtil.getLabelToolTipData(1) + "\n" + PetUtil.getGrowthTitleTipData(this._petInfo.growth);
                    }
                }
                else 
                {
                    this._labelTip.data = PetUtil.getLabelToolTipData(0) + "\n" + PetUtil.getSpiritTitleTipData(this._petInfo.spirit);
                }
            }
            return;
        }

        /* internal  */onTxtMouseOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as Object /* flash.text.TextField */;
            if (this._labelTip && this._attrSprite.contains(this._labelTip)) 
            {
                this._attrSprite.removeChild(this._labelTip);
            }
            return;
        }

        public updateByPetInfo(arg1: SPetInfo): void
        {
            this._petInfo = arg1;
            if (arg1) 
            {
                this.updateModelSprite(arg1);
                this.updateBaseSprite(arg1);
                this.updateAttrSprite(arg1);
                this.updateSkillSprite(arg1);
            }
            else 
            {
                this.clear();
            }
            return;
        }

        /* internal  */updateModelSprite(arg1: SPetInfo): void
        {
            var loc3=null;
            var loc4=null;
            var loc1="";
            var loc2="";
            if (arg1) 
            {
                this.rebornTimeBitmapData = arg1.reinLevel;
                this._petModel.updateModelByModelId(PetUtil.getShowModelId(arg1));
                if (arg1.sex != 0) 
                {
                    this._sexTxt.text = Language.getString(54237);
                }
                else 
                {
                    this._sexTxt.text = Language.getString(54236);
                }
                if (arg1.code != arg1.changeCode) 
                {
                    loc2 = HTMLUtil.addColor(Language.getString(54238), GlobalStyle.color6);
                }
                this._nameTxt.htmlText = loc2 + PetColor.getColorName(arg1);
                this._tileItem.petInfo = arg1;
                this._talentTxt.htmlText = HTMLUtil.addColor(arg1.talent.toString(), PetColor.getTalentColor(arg1).color);
                if (loc3 = CareerConfig.instance.getInfoByCode(arg1.career)) 
                {
                    if (PetUtil.getCareer(loc3.code) != ECareer._ECareerPetPhysical) 
                    {
                        if (PetUtil.getCareer(loc3.code) != ECareer._ECareerPetMagic) 
                        {
                            if (PetUtil.getCareer(loc3.code) == ECareer._ECareerPetPhysique) 
                            {
                                this._typeBtn.styleName = ResFileConst.Ling;
                                loc4 = Language.getString(54241);
                            }
                        }
                        else 
                        {
                            this._typeBtn.styleName = ResFileConst.Mo;
                            loc4 = Language.getString(54240);
                        }
                    }
                    else 
                    {
                        this._typeBtn.styleName = ResFileConst.Wu;
                        loc4 = Language.getString(54239);
                    }
                    loc4 = loc4 + Language.getString(54242);
                    this._typeBtn.toolTipData = "<textFormat leading=\'3\'>" + HTMLUtil.addColor(loc4, "#FFFFFF") + "</textFormat>";
                    this._typeBtn.drawNow();
                }
            }
            return;
        }

        /* internal  */updateBaseSprite(arg1: SPetInfo): void
        {
            var loc2=NaN;
            var loc1=null;
            if (arg1) 
            {
                loc1 = arg1.fightAttribute;
                this._lifeBar.setValue(arg1.life, loc1.maxLife);
                if (this._backName != arg1.name) 
                {
                    this._nameInput.text = arg1.name;
                    this._backName = arg1.name;
                }
                this._lifespanBar.setValue(int(arg1.lifeSpan / 5), int(arg1.maxLifeSpan / 5));
                loc2 = PetExperienceConfig.instance.getValueByLevel(arg1.level);
                this._levelTxt.text = arg1.level.toString();
            }
            return;
        }

        /* internal  */updateAttrSprite(arg1: SPetInfo): void
        {
            var loc1=[];
            var loc2=[];
            var loc3=null;
            if (arg1) 
            {
                this._spiritTxt.htmlText = HTMLUtil.addColor(Language.getString(54243) + arg1.spirit.toString(), PetUtil.getSpiritTitleColor(arg1.spirit));
                this._growthTxt.htmlText = HTMLUtil.addColor(Language.getString(54244) + arg1.growth.toString(), PetUtil.getGrowthTitleColor(arg1.growth));
                loc3 = arg1.fightAttribute;
                loc1.push(loc3.physicalAttack);
                loc1.push(loc3.magicAttack);
                loc1.push(loc3.physicalDefense);
                loc1.push(loc3.magicDefense);
                loc1.push(loc3.hit);
                loc1.push(loc3.jouk);
                loc1.push(loc3.physicalCrit + loc3.magicCrit);
                loc2 = PetUtil.getSpiritAddValueArray(arg1);
                loc1.push(loc3.power);
                loc1.push(loc3.agile);
                loc1.push(loc3.habitus);
                loc1.push(loc3.brains);
                loc1.push(loc3.spiritual);
                loc2 = loc2.concat(PetUtil.getGrowthAddValueArray(arg1));
                this._fightAttrPanel.updateValue(loc1.slice(0, 7));
                this._fightAttrPanel.updateAddValue(loc2.slice(0, 7));
                this._baseAttrPanel.updateValue(loc1.slice(7, 12));
                this._baseAttrPanel.updateAddValue(loc2.slice(10, 15));
            }
            return;
        }

        /* internal  */getAdditionBySpirit(arg1: int): string
        {
            var loc2=NaN;
            var loc1="";
            if (this._petInfo) 
            {
                loc2 = arg1 * this._petInfo.spirit / 10;
                loc1 = "（+" + Math.floor(loc2) + "）";
            }
            return loc1;
        }

        /* internal  */updateSkillSprite(arg1: SPetInfo): void
        {
            this._skillListPanel.petInfo = arg1;
            return;
        }

        /* internal  */getTileTipData(): string
        {
            var loc1=null;
            if (this._petInfo) 
            {
                loc1 = PetUtil.getPetTitleTipData(this._petInfo.growth, this._petInfo.spirit);
            }
            return loc1;
        }

        /* internal  */getTitle(): string
        {
            var loc2=null;
            var loc1="";
            if (this._petInfo) 
            {
                loc2 = PetUtil.getPetTitle(this._petInfo.growth, this._petInfo.spirit);
                if (loc2 != "") 
                {
                    loc1 = "<font size=\'14\'><b>" + loc2 + "</b></font> ● ";
                }
            }
            return loc1;
        }

        /* internal  */ChangeModelSuccessHandler(): void
        {
            PetShareObject.save(PetShareObject.ChangeModelKey);
            return;
        }

        /* internal  */onJianBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            GameController.petIllu.view.show();
            return;
        }

        public clear(): void
        {
            this.rebornTimeBitmapData = 0;
            this._sexTxt.text = "";
            this._nameTxt.text = "";
            this._petModel.clean();
            this._typeBtn.toolTipData = "";
            this._talentTxt.text = "";
            this._lifeBar.setValue(0, 0);
            this._nameInput.text = "";
            this._lifespanBar.setValue(0, 0);
            this._levelTxt.text = "";
            this._spiritTxt.text = "";
            this._growthTxt.text = "";
            this._fightAttrPanel.clear();
            this._baseAttrPanel.clear();
            this._skillListPanel.clear();
            return;
        }

        /* internal */ /* var */_spiritTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_fightAttrPanel: PetAttrPanel;

        /* internal */ /* var */_growthTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_baseAttrPanel: PetAttrPanel;

        /* internal */ /* var */_skillListPanel: PetInfoSkillListPanel;

        /* internal */ /* var */_labelTip: BgLabelToolTip;

        /* internal */ /* var */_fightAttrLabelArray: Array<any>;

        /* internal */ /* var */_titleTxt: GTextFiled;

        /* internal */ /* var */_skillItemArray: Array<any>;

        /* internal */ /* var */_petInfo: SPetInfo;

        /* internal */ /* var */_maxSpirit: int=20;

        /* internal */ /* var */_maxGrowth: int=40;

        /* internal */ /* var */_backName: string;

        /* internal */ /* var */_rebornTimePic: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_isUpgrade: Boolean=false;

        /* internal */ /* var */_modelSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_baseSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_attrSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_skillSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_sexTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_tileItem: PetTileItem;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_typeBtn: GLoadedButton;

        /* internal */ /* var */_jianBtn: GLoadedButton;

        /* internal */ /* var */_talentLabel: GTextFiled;

        /* internal */ /* var */_baseAttrLabelArray: Array<any>;

        /* internal */ /* var */_talentTxt: GTextFiled;

        /* internal */ /* var */_petModel: PetModelPanel;

        /* internal */ /* var */_lifeBar: PetProcessBar;

        /* internal */ /* var */_lifespanBar: PetProcessBar;

        /* internal */ /* var */_nameInput: GTextInput;

        /* internal */ /* var */_levelTxt: Object /* flash.text.TextField */;
    }
